
* sourcing_alt_1: Excluded products, but not excluded sellers 

estimates clear
local VAR  sourcing_alt_1   
foreach v of local VAR{
	
eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month    signatory  ///
 ln_q_b_all age_buy_month ///
  ln_p_inpf_sbjo ln_q_sbjo ///
if sample==1, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b  ) vce (cluster b_id)
}


* when values / volumes used, drop outliers -- otherwise tiny numbers in one the tail
* sourcing_alt_4: Excluded products, sellers / volume  (N=13,593)
* sourcing_alt_5: Excluded products, sellers / values  (N=13,067)

local VAR  sourcing_alt_4 sourcing_alt_5
foreach v of local VAR{
	
capture drop p99
capture drop p01
_pctile `v' if n_b==1 & b_in_sample==1 , percentiles(2 98)
gen p99=r(r2)
gen p01=r(r1)

eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1 & `v'>p01 & `v'<p99, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month    signatory  ///
 ln_q_b_all age_buy_month ///
  ln_p_inpf_sbjo ln_q_sbjo ///
if sample==1 & `v'>p01 & `v'<p99, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b  ) vce (cluster b_id)
}


* sourcing_alt_6: Excluded products, excluding main sellers bjy (N=14,919)
* sourcing_alt_7: Excluded products, excluding first 6 months (N=15,361)
* sourcing_alt_8: Excluded products, excluding first year (N=15,312)

local VAR  sourcing_alt_6 sourcing_alt_7 sourcing_alt_8   
foreach v of local VAR{
	
eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month    signatory  ///
 ln_q_b_all age_buy_month ///
  ln_p_inpf_sbjo ln_q_sbjo ///
if sample==1, ///
abs(gr_sjt top_dest_b  cohort_sb cohort_b  ) vce (cluster b_id)
}


esttab estp_* estmu_* using "${tables}\TableD3PanelA.tex", replace ///
	b(3) se(3) ///
	booktabs  alignment(D{.}{.}{1.3}) star(* 0.10 ** 0.05 *** 0.01) substitute("\sym{*}" "*" "\sym{**}" "**""\sym{***}" "***") ///
	keep(S_sourcing_alt_1 S_sourcing_alt_4 S_sourcing_alt_5 S_sourcing_alt_6 S_sourcing_alt_7 S_sourcing_alt_8) wrap ///
	compress varwidth(30) nonotes nonumber nomtitles noobs prehead(" ") postfoot("\midrule \addlinespace") ///
	nolines posthead("`numbers'") prefoot("\midrule")
	 

* Recall: incl_sourcing_metric_b: Included products
* Baseline:  sourcing sourcing_baseline

* ---------------------------------------------------------------------------- *
* Measures based on duration 
* ---------------------------------------------------------------------------- *

* wav_num_m_sb: weighted average of the duration (count of effective months of trade) 
* FE_num_m_sb: fixed effects of the duration  

estimates clear
local VAR wav_num_m_sb FE_num_m_sb 
foreach v of local VAR{

eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo   ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

}

esttab estp_* estmu_* using "${tables}\TableD3PanelB.tex", replace ///
	b(3) se(3) ///
	booktabs  alignment(D{.}{.}{1.3}) star(* 0.10 ** 0.05 *** 0.01) substitute("\sym{*}" "*" "\sym{**}" "**""\sym{***}" "***") ///
	keep(S_wav_num_m_sb S_FE_num_m_sb) wrap ///
	compress varwidth(30) nonotes nonumber nomtitles noobs prehead(" ") postfoot("\midrule \addlinespace") ///
	nolines posthead("`numbers'") prefoot("\midrule")

* ---------------------------------------------------------------------------- *
* Measures based on concentration
* ---------------------------------------------------------------------------- *

estimates clear
* Only using sellers accounting for x of the volume
local VAR  nl_s50  nl_s70   nq_s50  nq_s70 
foreach v of local VAR{

eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo   ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

}

* Share of transactions explained by the top 1, 3 and 5 sellers

local VAR  sourcing_l_1 sourcing_l_3 sourcing_l_5
foreach v of local VAR{

eststo estp_`v': reghdfe ln_p_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo  ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

eststo estmu_`v': reghdfe ln_mu_sbjo  S_`v'  ln_q_sb_all sh_s_b sh_b_s age_buysel_month signatory  ///
 ln_q_b_all age_buy_month ln_p_inpf_sbjo ln_q_sbjo   ///
if sample==1, ///
abs(gr_sjt top_dest_b cohort_sb cohort_b) vce (cluster b_id)

}

esttab estp_* estmu_* using "${tables}\TableD3PanelC.tex", replace ///
	b(3) se(3) ///
	booktabs  alignment(D{.}{.}{1.3}) star(* 0.10 ** 0.05 *** 0.01) substitute("\sym{*}" "*" "\sym{**}" "**""\sym{***}" "***") ///
	keep(S_nl_s50  S_nl_s70  S_nq_s50  S_nq_s70  S_sourcing_l_1 S_sourcing_l_3 S_sourcing_l_5 ) wrap ///
	compress varwidth(30) nonotes nonumber nomtitles noobs prehead(" ") postfoot("\midrule \addlinespace") ///
	nolines posthead("`numbers'") prefoot("\midrule")

